package com.lmsservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lmsservice.common.R;
import com.lmsservice.entity.Rules;
import com.lmsservice.service.RulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rules")
public class RulesController {

    @Autowired
    private RulesService rulesService;

    @PutMapping
    public R<String> update(@RequestBody Rules rules){

        rulesService.updateById(rules);
        return R.success("修改成功");
    }

    @GetMapping
    public R<Rules> get(Long id){
        LambdaQueryWrapper<Rules> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(id!=0,Rules::getId,id);
        return R.success(rulesService.getOne(queryWrapper));
    }
}
